﻿Partial Public Class TrabajoFinalABM
    Inherits System.Web.UI.Page

    Dim ocnTrabajoFinal As New CapaNegocio.TrabajoFinal()
    Dim ocnNotas As New CapaNegocio.Notas

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.CalendarioFechaAlta.Text = DateTime.Now.ToString("d")
        'cargargrilla()
    End Sub

    Protected Sub ButtonGuardar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonGuardar.Click
        Try
            ocnTrabajoFinal.InsertarTrabajoFinal(Me.TextBoxNroExpediente.Text _
                                     , Me.TextBoxDniAlumno1.Text _
                                     , Me.TextBoxTituloTrabajo.Text _
                                     , Me.TextBoxProfesorGuiaDni.Text _
                                     , Me.TextBoxProfesorAsesorDni.Text _
                                     , CDate(Me.CalendarioFechaAlta.Text) _
                                     , CDate(Me.CalendarUltimoExamen.Text) _
                                     , Me.TextBoxPlanEstudios.Text)
            'cargargrilla()
        Catch ex As Exception
            Session.Add("exError", ex)
            Response.Redirect("ManejarError.aspx")
        End Try
    End Sub

    Function cargargrillaTA(ByVal nroExpediente As String)
        Dim ds As New DataSet
        ds = ocnTrabajoFinal.obtenerTrabajosAprobados(nroExpediente)
        Me.GridViewTrabajos.DataSource = ds.Tables(0)
        Me.GridViewTrabajos.DataBind()
        Return Me.GridViewTrabajos
    End Function

    Function cargargrillaCAL(ByVal nroExpediente As String)
        Dim ds As New DataSet

        ds = ocnNotas.obtenerNotasProfesores(nroExpediente)

        Me.GridViewProfesoresCAL.DataSource = ds.Tables(0)

        Me.GridViewProfesoresCAL.DataBind()
        Return Me.GridViewProfesoresCAL
    End Function


    Function cargargrillaAN(ByVal nroExpediente As String)
        Dim ds As New DataSet

        ds = ocnNotas.obtenerNotas(nroExpediente)

        Me.GridViewNotas.DataSource = ds.Tables(0)

        Me.GridViewNotas.DataBind()
        Return Me.GridViewNotas
    End Function



    Protected Sub ButtonMostrarTA_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonMostrarTA.Click
        Try
            cargargrillaTA(Me.TextBoxNroExpediente.Text)
        Catch ex As Exception
            Session.Add("exError", ex)
            Response.Redirect("ManejarError.aspx")
        End Try
    End Sub

    Protected Sub ButtonRegistrarTA_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonRegistrarTA.Click
        Try
            ocnTrabajoFinal.InsertarNroResolucionTA(Me.TextBoxNroResolucionTA.Text _
                                                            , Me.TextBoxNroExpediente.Text _
                                                            , CDate(Me.TextBoxFechaTA.Text))
            cargargrillaTA(Me.TextBoxNroExpediente.Text)
        Catch ex As Exception
            Session.Add("exError", ex)
            Response.Redirect("ManejarError.aspx")
        End Try
    End Sub

    Protected Sub ButtonAgregarProfesor_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonAgregarProfesor.Click
        Try
            ocnNotas.InsertarNotaProfesor(Me.TextBoxNroExpediente.Text, Me.TextBoxDniProfesor.Text)
            cargargrillaCAL(Me.TextBoxNroExpediente.Text)
        Catch ex As Exception
            Session.Add("exError", ex)
            Response.Redirect("ManejarError.aspx")
        End Try
    End Sub

    Protected Sub ButtonRegistrarCAL_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonRegistrarCAL.Click
        Try
            ocnNotas.InsertarNroResolucionCAL(Me.TextBoxNroResolucionCAL.Text, Me.TextBoxNroExpediente.Text _
                                                     , CDate(Me.TextBoxFechaCAL.Text))

            cargargrillaCAL(Me.TextBoxNroExpediente.Text)
        Catch ex As Exception
            Session.Add("exError", ex)
            Response.Redirect("ManejarError.aspx")
        End Try
    End Sub

    Protected Sub ButtonMostrarCAL_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonMostrarCAL.Click
        Try
            cargargrillaCAL(Me.TextBoxNroExpediente.Text)
        Catch ex As Exception
            Session.Add("exError", ex)
            Response.Redirect("ManejarError.aspx")
        End Try
    End Sub

    Private Sub ButtonMostrarAN_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonMostrarAN.Click
        Try
            cargargrillaAN(Me.TextBoxNroExpediente.Text)
        Catch ex As Exception
            Session.Add("exError", ex)
            Response.Redirect("ManejarError.aspx")
        End Try
    End Sub

    Private Sub ButtonRegistrarAN_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonRegistrarAN.Click
        Try
            ocnNotas.InsertarNroResolucionAN(Me.TextBoxNroResolucionAN.Text _
                                                    , Me.TextBoxNroExpediente.Text _
                                                    , CDate(Me.TextBoxFechaAN.Text))
            cargargrillaAN(Me.TextBoxNroExpediente.Text)
        Catch ex As Exception
            Session.Add("exError", ex)
            Response.Redirect("ManejarError.aspx")
        End Try
    End Sub
End Class